{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "Kronos学习",
   "id": "f80ca263226b189"
  },
  {
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-09-04T08:58:44.418987Z",
     "start_time": "2025-09-04T08:58:38.112454Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from model import Kronos, KronosTokenizer, KronosPredictor\n",
    "# Load from Hugging Face Hub\n",
    "tokenizer = KronosTokenizer.from_pretrained(\"NeoQuasar/Kronos-Tokenizer-base\")\n",
    "model = Kronos.from_pretrained(\"NeoQuasar/Kronos-small\")"
   ],
   "id": "fb5d8800acb72f31",
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'safetensors' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001B[31m---------------------------------------------------------------------------\u001B[39m",
      "\u001B[31mNameError\u001B[39m                                 Traceback (most recent call last)",
      "\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[11]\u001B[39m\u001B[32m, line 3\u001B[39m\n\u001B[32m      1\u001B[39m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mmodel\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m Kronos, KronosTokenizer, KronosPredictor\n\u001B[32m      2\u001B[39m \u001B[38;5;66;03m# Load from Hugging Face Hub\u001B[39;00m\n\u001B[32m----> \u001B[39m\u001B[32m3\u001B[39m tokenizer = \u001B[43mKronosTokenizer\u001B[49m\u001B[43m.\u001B[49m\u001B[43mfrom_pretrained\u001B[49m\u001B[43m(\u001B[49m\u001B[33;43m\"\u001B[39;49m\u001B[33;43mNeoQuasar/Kronos-Tokenizer-base\u001B[39;49m\u001B[33;43m\"\u001B[39;49m\u001B[43m)\u001B[49m\n\u001B[32m      4\u001B[39m model = Kronos.from_pretrained(\u001B[33m\"\u001B[39m\u001B[33mNeoQuasar/Kronos-small\u001B[39m\u001B[33m\"\u001B[39m)\n",
      "\u001B[36mFile \u001B[39m\u001B[32m/opt/miniconda3/envs/Kronos_env/lib/python3.12/site-packages/huggingface_hub/utils/_validators.py:114\u001B[39m, in \u001B[36mvalidate_hf_hub_args.<locals>._inner_fn\u001B[39m\u001B[34m(*args, **kwargs)\u001B[39m\n\u001B[32m    111\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m check_use_auth_token:\n\u001B[32m    112\u001B[39m     kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.\u001B[34m__name__\u001B[39m, has_token=has_token, kwargs=kwargs)\n\u001B[32m--> \u001B[39m\u001B[32m114\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mfn\u001B[49m\u001B[43m(\u001B[49m\u001B[43m*\u001B[49m\u001B[43margs\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43m*\u001B[49m\u001B[43m*\u001B[49m\u001B[43mkwargs\u001B[49m\u001B[43m)\u001B[49m\n",
      "\u001B[36mFile \u001B[39m\u001B[32m/opt/miniconda3/envs/Kronos_env/lib/python3.12/site-packages/huggingface_hub/hub_mixin.py:566\u001B[39m, in \u001B[36mModelHubMixin.from_pretrained\u001B[39m\u001B[34m(cls, pretrained_model_name_or_path, force_download, resume_download, proxies, token, cache_dir, local_files_only, revision, **model_kwargs)\u001B[39m\n\u001B[32m    563\u001B[39m     \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mcls\u001B[39m._hub_mixin_inject_config \u001B[38;5;129;01mand\u001B[39;00m \u001B[33m\"\u001B[39m\u001B[33mconfig\u001B[39m\u001B[33m\"\u001B[39m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;129;01min\u001B[39;00m model_kwargs:\n\u001B[32m    564\u001B[39m         model_kwargs[\u001B[33m\"\u001B[39m\u001B[33mconfig\u001B[39m\u001B[33m\"\u001B[39m] = config\n\u001B[32m--> \u001B[39m\u001B[32m566\u001B[39m instance = \u001B[38;5;28;43mcls\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_from_pretrained\u001B[49m\u001B[43m(\u001B[49m\n\u001B[32m    567\u001B[39m \u001B[43m    \u001B[49m\u001B[43mmodel_id\u001B[49m\u001B[43m=\u001B[49m\u001B[38;5;28;43mstr\u001B[39;49m\u001B[43m(\u001B[49m\u001B[43mmodel_id\u001B[49m\u001B[43m)\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m    568\u001B[39m \u001B[43m    \u001B[49m\u001B[43mrevision\u001B[49m\u001B[43m=\u001B[49m\u001B[43mrevision\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m    569\u001B[39m \u001B[43m    \u001B[49m\u001B[43mcache_dir\u001B[49m\u001B[43m=\u001B[49m\u001B[43mcache_dir\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m    570\u001B[39m \u001B[43m    \u001B[49m\u001B[43mforce_download\u001B[49m\u001B[43m=\u001B[49m\u001B[43mforce_download\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m    571\u001B[39m \u001B[43m    \u001B[49m\u001B[43mproxies\u001B[49m\u001B[43m=\u001B[49m\u001B[43mproxies\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m    572\u001B[39m \u001B[43m    \u001B[49m\u001B[43mresume_download\u001B[49m\u001B[43m=\u001B[49m\u001B[43mresume_download\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m    573\u001B[39m \u001B[43m    \u001B[49m\u001B[43mlocal_files_only\u001B[49m\u001B[43m=\u001B[49m\u001B[43mlocal_files_only\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m    574\u001B[39m \u001B[43m    \u001B[49m\u001B[43mtoken\u001B[49m\u001B[43m=\u001B[49m\u001B[43mtoken\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m    575\u001B[39m \u001B[43m    \u001B[49m\u001B[43m*\u001B[49m\u001B[43m*\u001B[49m\u001B[43mmodel_kwargs\u001B[49m\u001B[43m,\u001B[49m\n\u001B[32m    576\u001B[39m \u001B[43m\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m    578\u001B[39m \u001B[38;5;66;03m# Implicitly set the config as instance attribute if not already set by the class\u001B[39;00m\n\u001B[32m    579\u001B[39m \u001B[38;5;66;03m# This way `config` will be available when calling `save_pretrained` or `push_to_hub`.\u001B[39;00m\n\u001B[32m    580\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m config \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;129;01mand\u001B[39;00m (\u001B[38;5;28mgetattr\u001B[39m(instance, \u001B[33m\"\u001B[39m\u001B[33m_hub_mixin_config\u001B[39m\u001B[33m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m) \u001B[38;5;129;01min\u001B[39;00m (\u001B[38;5;28;01mNone\u001B[39;00m, {})):\n",
      "\u001B[36mFile \u001B[39m\u001B[32m/opt/miniconda3/envs/Kronos_env/lib/python3.12/site-packages/huggingface_hub/hub_mixin.py:807\u001B[39m, in \u001B[36mPyTorchModelHubMixin._from_pretrained\u001B[39m\u001B[34m(cls, model_id, revision, cache_dir, force_download, proxies, resume_download, local_files_only, token, map_location, strict, **model_kwargs)\u001B[39m\n\u001B[32m    795\u001B[39m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[32m    796\u001B[39m     model_file = hf_hub_download(\n\u001B[32m    797\u001B[39m         repo_id=model_id,\n\u001B[32m    798\u001B[39m         filename=constants.SAFETENSORS_SINGLE_FILE,\n\u001B[32m   (...)\u001B[39m\u001B[32m    805\u001B[39m         local_files_only=local_files_only,\n\u001B[32m    806\u001B[39m     )\n\u001B[32m--> \u001B[39m\u001B[32m807\u001B[39m     \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mcls\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_load_as_safetensor\u001B[49m\u001B[43m(\u001B[49m\u001B[43mmodel\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmodel_file\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmap_location\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mstrict\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m    808\u001B[39m \u001B[38;5;28;01mexcept\u001B[39;00m EntryNotFoundError:\n\u001B[32m    809\u001B[39m     model_file = hf_hub_download(\n\u001B[32m    810\u001B[39m         repo_id=model_id,\n\u001B[32m    811\u001B[39m         filename=constants.PYTORCH_WEIGHTS_NAME,\n\u001B[32m   (...)\u001B[39m\u001B[32m    818\u001B[39m         local_files_only=local_files_only,\n\u001B[32m    819\u001B[39m     )\n",
      "\u001B[36mFile \u001B[39m\u001B[32m/opt/miniconda3/envs/Kronos_env/lib/python3.12/site-packages/huggingface_hub/hub_mixin.py:831\u001B[39m, in \u001B[36mPyTorchModelHubMixin._load_as_safetensor\u001B[39m\u001B[34m(cls, model, model_file, map_location, strict)\u001B[39m\n\u001B[32m    829\u001B[39m \u001B[38;5;129m@classmethod\u001B[39m\n\u001B[32m    830\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34m_load_as_safetensor\u001B[39m(\u001B[38;5;28mcls\u001B[39m, model: T, model_file: \u001B[38;5;28mstr\u001B[39m, map_location: \u001B[38;5;28mstr\u001B[39m, strict: \u001B[38;5;28mbool\u001B[39m) -> T:\n\u001B[32m--> \u001B[39m\u001B[32m831\u001B[39m     \u001B[38;5;28;01mif\u001B[39;00m packaging.version.parse(\u001B[43msafetensors\u001B[49m.__version__) < packaging.version.parse(\u001B[33m\"\u001B[39m\u001B[33m0.4.3\u001B[39m\u001B[33m\"\u001B[39m):  \u001B[38;5;66;03m# type: ignore [attr-defined]\u001B[39;00m\n\u001B[32m    832\u001B[39m         load_model_as_safetensor(model, model_file, strict=strict)  \u001B[38;5;66;03m# type: ignore [arg-type]\u001B[39;00m\n\u001B[32m    833\u001B[39m         \u001B[38;5;28;01mif\u001B[39;00m map_location != \u001B[33m\"\u001B[39m\u001B[33mcpu\u001B[39m\u001B[33m\"\u001B[39m:\n",
      "\u001B[31mNameError\u001B[39m: name 'safetensors' is not defined"
     ]
    }
   ],
   "execution_count": 11
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
